package com.example.travelapplication.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager2.adapter.FragmentStateAdapter;
import androidx.viewpager2.widget.ViewPager2;

import android.media.Image;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;

import com.example.travelapplication.R;
import com.example.travelapplication.adapter.FragmentAdapter;
import com.google.android.material.floatingactionbutton.FloatingActionButton;

public class MainActivity extends AppCompatActivity {

    private ImageButton btn_home;
    private ImageButton btn_like;
    private ImageButton btn_mine;
    private ImageButton btn_setting;
    private FloatingActionButton float_btn;
    private ViewPager2 viewPager2;
    private FragmentStateAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
    }

    private void init(){
        btn_home = (ImageButton)findViewById(R.id.btn_home);
        btn_like = (ImageButton)findViewById(R.id.btn_like);
        btn_mine = (ImageButton)findViewById(R.id.btn_mine);
        btn_setting = (ImageButton)findViewById(R.id.btn_setting);
        float_btn = (FloatingActionButton)findViewById(R.id.float_btn);
        viewPager2 = (ViewPager2)findViewById(R.id.viewPager2);

        btn_home.setOnClickListener(listener1);
        btn_like.setOnClickListener(listener1);
        btn_mine.setOnClickListener(listener1);
        btn_setting.setOnClickListener(listener1);
        float_btn.setOnClickListener(listener2);

        adapter = new FragmentAdapter(getSupportFragmentManager(), getLifecycle());
        viewPager2.setAdapter(adapter);
    }

    private View.OnClickListener listener1 = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()){
                case R.id.btn_home:
                    viewPager2.setCurrentItem(0);
                    break;
                case R.id.btn_like:
                    viewPager2.setCurrentItem(1);
                    break;
                case R.id.btn_mine:
                    viewPager2.setCurrentItem(2);
                    break;
                case R.id.btn_setting:
                    viewPager2.setCurrentItem(3);
                    break;
            }
        }
    };

    private View.OnClickListener listener2 = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (viewPager2.getCurrentItem()){
                case 3:
                    viewPager2.setCurrentItem(0);
                    break;
                case 0:
                    viewPager2.setCurrentItem(1);
                    break;
                case 1:
                    viewPager2.setCurrentItem(2);
                    break;
                case 2:
                    viewPager2.setCurrentItem(3);
                    break;
            }
        }
    };
}